package com.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.dao.BookDao;
import com.dao.BookDaoImpl;

import vo.Book;

/**
 * Servlet implementation class UpdateBookServlet
 */
@WebServlet("/updateBook.do")
public class UpdateBookServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public UpdateBookServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
				//获得请求参数
		request.setCharacterEncoding("utf-8");
		Integer isbn=Integer.valueOf(request.getParameter("isbn"));
		String name=request.getParameter("bookname");
		Integer price=Integer.valueOf(request.getParameter("price"));
		Book book=new Book();
		book.setIsbn(isbn);
		book.setBookname(name);
		book.setPrice(price);
		//调用业务逻辑
		BookDao dao=new BookDaoImpl();
		dao.update(book);
		//转发请求
		response.sendRedirect("bookList.do");
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
